<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );
class MY_Controller extends CI_Controller {
	
	function checkUser($userId) {
		$sessionUserId = $this->session->userdata ( "userId" );
		if (empty ( $userId ) || $userId == 0 || $sessionUserId != $userId) {
			$this->load->view ( "login" );
			$this->load->view ( "footers/footer02" );
		} else {
			return true;
		}
	}
	function gotoUser($userId) {
		if ($this->checkUser ( $userId )) {
			/*$data = $this->user_model->getTeamInfo ( array ("userId" => $userId ) );
			$url = base_url ( "index.php/team/index" );
			$home_url = base_url ( "index.php/user/index" . $this->session->userdata ( "userId" ) );
			$divCode = "$('#getTeamListInfo').wjTeamList({source:$data,url:'$url'});";
			$this->load->view ( 'headers/header01', array ("divCode" => $divCode, "houmeUrl" => $home_url, "myHome" => base_url ( "index.php/user_home/index/" . $this->session->userdata ( "userId" ) ) ) );
			*/
			$this->getHeader ();
			$this->load->view ( "user/grzy" );
			$this->load->view ( "footers/footer01" );
		}
	}
	function getHeader() {
		$this->load->model ( 'user_model' );
		$userId=$this->session->userdata("userId");
		$data = $this->user_model->getTeamInfo ( array ("userId" =>$userId ) );
		$url = base_url ( "index.php/team/index" );
		$home_url = base_url ( "index.php/user/index/$userId");
		$divCode = "$('#getTeamListInfo').wjTeamList({source:$data,url:'$url'});";
		$friend_list=base_url("index.php/user_home/friendListPage/".$userId);
		$this->load->view ( 'headers/header01', array ("divCode" => $divCode, "friendList"=>$friend_list,"houmeUrl" => $home_url, "myHome" => base_url ( "index.php/user_home/index/" . $this->session->userdata ( "userId" ) ) ) );
	
	}
	function checkState($userId) {
		$this->load->library ( 'session' );
		$state = 1;
		$array = array ();
		$sessionUserId = $this->session->userdata ( "userId" );
		if ($sessionUserId != $userId) {
			$state = 0;
		}
		return $state;
	
	}
	function getUserIdSession() {
		
		return $this->session->userdata ( "userId" );
	}
	
	/**
	 * Enter description here ...
	 */
	public function getHomeDynamicDiv($data, $state, $type) {
		$this->load->library ( "code_fragment" );
		return $this->code_fragment->homeDynamicDiv ( $data, $state, $type );
	}
	
	function loginOut() {
		$this->session->sess_destroy();
	}
	
	function getFriendsList($userId) {
		$this->load->model("friendsreferral_model");
		$this->load->library("code_fragment");
		$tableData  = $this->friendsreferral_model->getAllFriendsInfo(array("userId"=>$userId));
		$state      =($this->session->userdata("userdata")==$userId);
		$divCode 	= $this->code_fragment->getPersonalTag($tableData,$state);
		return $divCode;
	}
	
}

	

